package com.baichang.taoshunda.controller.mobile.delivery;

import com.baichang.framework.controller.BaseMobileController;
import com.baichang.framework.controller.IService;
import com.baichang.framework.excelption.ServiceException;
import com.baichang.taoshunda.controller.ControllerConstants;
import com.baichang.taoshunda.entity.Html;
import com.baichang.taoshunda.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by ${wushenglu} on 17/08/28.
 */
@Controller
@RequestMapping(ControllerConstants.MINE)
public class AbuoutUsMCtronller extends BaseMobileController {

    @Autowired
    private ParamsService paramsService;
    @Autowired
    private AppVersionService appVersionService;
    @Autowired
    private LinkUrlService linkUrlService;
    @Autowired
    private DeliveryBlanceService deliveryBlanceService;
    @Autowired
    private HtmlService htmlService;


    /**
     * 联系客服
     *
     * @param request
     * @param response
     */
    @RequestMapping("/contactService")
    public void getAboutInfo(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String s) throws ServiceException {
                return paramsService.getParamsValue(21, 21);
            }
        });
    }

    /**
     * 查看版本信息
     *
     * @param request
     * @param response
     */
    @RequestMapping("/checkAppVersion")
    public void checkAppVersion(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest request, HttpServletResponse response, String json) throws ServiceException {
                Integer version = getInt(json, "version", 0);
                Integer platform = getInt(json, "platform", 0);
                return appVersionService.checkAppVersion(version, platform);
            }
        });
    }

    /**
     * 关于我们
     *
     * @param request
     * @param response
     */
    @RequestMapping("/getConstantsUs")
    public void getConstantsUs(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest request, HttpServletResponse response, String json) throws ServiceException {
                return linkUrlService.getConstantsUsUrlById(4);
            }
        });
    }

    /**
     * 查看配送员钱包
     *
     * @param request
     * @param response
     */
    @RequestMapping("/findDeliveryWallet")
    public void findDeliveryWallet(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest request, HttpServletResponse response, String json) throws ServiceException {
                Integer disId = getInt(json, "disId", 0);
                return deliveryBlanceService.findDeliveryWallet(disId);
            }
        });
    }
    /**
     * 用户协议
     *
     * @param request
     * @param response
     * @param model
     * @return
     */
    @RequestMapping("/userAgreement")
    public String userAgreement(HttpServletRequest request, HttpServletResponse response, Model model)throws ServiceException {
        Html content = htmlService.queryById(3);
        model.addAttribute("content",content.getValue());
        return "taoshunda/aboutUs";
    }
}
